package com.woniuxy.TransactionPC;

import com.woniuxy.model.entity.TransactionOrder;
import com.woniuxy.service.TransactionOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RabbitMQConsumer {

    @Autowired
    private TransactionOrderService transactionOrderService;

    @RabbitListener(queues = "transaction_order_queue")
    public void createTransactionOrder(TransactionOrder transactionOrder) {
        try {
            System.out.println("Received order creation request: " + transactionOrder);
            transactionOrderService.createTransactionOrder(transactionOrder);
            System.out.println("Order created successfully: " + transactionOrder.getOrderNo());
        } catch (Exception e) {
            System.err.println("Failed to create order: " + transactionOrder.getOrderNo());
            e.printStackTrace();
        }
    }
}